<?php

require_once "Zend/Db/Table.php";

class Default_UserMapper implements IUserMapper {

    /**
     * @var Zend_Db_Adapter_Pdo_Abstract
     */
    private $_db;

    public function __construct() {
        $this->_db = Zend_Db_Table::getDefaultAdapter();
    }

    public function findUser($email, $pass, $key)
    {
        $database = Zend_Db_Table::getDefaultAdapter();

        print_r($database);
        exit();

//         $select = $this->_getFetchAllSelectQuery()
//         ->where('email = ?', $email);
//         $rows = $database->fetchAll($select);

        $sql = "SELECT *
                FROM t_user
                WHERE email = ?";

//         $database->

//         if(!$rows || count($rows) != 1)
//             return null;

//         $row = $rows[0];

//         if ($row["password"] != sha1($key . $row["salt"] . $pass))
//             return null;

//         return $row;
        return array(
            'idUser' => 1,
            'login' => '1',
            'email' => '1@1.com',
        );
    }

    public function userExists_byIdAndPass($userID, $pass, $key) {
        return false;
    }
    public function findUsersByParams($params) {
        return array();
    }
    public function addUser($publicName, $email, $password/*, $firstName, $lastName*/) {}
    public function updateUser($idUser, $data) {}


    public function getFriendsByUserID($idUser) {

        $sql = "SELECT us.idUser AS friendId, us.publicName AS friendLogin
                FROM t_user us
                JOIN rt_user_friend fr ON (fr.idUser = us.idUser OR fr.idFriend = us.idUser)
                WHERE (fr.idUser = ? OR fr.idFriend = ?) AND us.idUser != ?
                ORDER BY us.publicName ASC";
        $binds = array($idUser, $idUser, $idUser);
        $results = $this->_db->fetchAll($sql, $binds);
        return $results;
    }

    public function getRequestsByUserID($idUser) {
        return array();
    }
    public function addRequest($idUser, $idFriend) {}
    public function userExists_byPublicName($publicName) {
        return false;
    }

}
